package xiangya.bysj.service.impl;

import java.util.List;


import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;


import xiangya.bysj.entity.Patient;
import xiangya.bysj.entity.User;
import xiangya.bysj.mapper.interf.PatientMapper;
import xiangya.bysj.service.interf.PatientServiceInterface;



//服药者服务类
@Service("patientService")
@Transactional(readOnly = false,rollbackFor=Exception.class ,propagation = Propagation.REQUIRED)
public class PatientServiceImpl implements PatientServiceInterface {


	//注入patientMapper
	@Resource
	private PatientMapper patientMapper;
	

	/*
	 * 参数要删除的id的list
	 * 
	 */
	@Override
	public void deletePatients(List<Integer> patientsID) throws Exception {
		patientMapper.deletePatients(patientsID);
	}

	/**
	 * 参数是要拿到的用户的服药者
	 * 返回服药者list
	 */
	@Override
	public List<Patient> findPatientsByUser(int userid) throws Exception {
		// TODO Auto-generated method stub
		return patientMapper.findPatientsByUser(userid);
	}
	
	/**
	 * 
	 * 添加服药者参数是服药者的list
	 */
	@Override
	public void savePatients(List<Patient> patients) throws Exception {
		// TODO Auto-generated method stub
		
		patientMapper.savePatients(patients);
	}

	@Override
	public void delete(int objId) throws Exception {
		// TODO Auto-generated method stub
		patientMapper.delete(objId);
	}

	@Override
	public void save(Patient obj) throws Exception {
		patientMapper.save(obj);
	}

	@Override
	public void update(Patient obj) throws Exception {
		// TODO Auto-generated method stub
		patientMapper.update(obj);
	}

	/**
	 * 返回服药者实体类通过服药者的id
	 * 参数是服药者的id 
	 */
	@Override
	public Patient findPatientById(int id) throws Exception { 
		// TODO Auto-generated method stub
		return patientMapper.findPatientById(id);
	}

	

	
	@Override
	public List<Patient> findPatientByName(String name) throws Exception {
		
		return patientMapper.findPatientByName(name);
	}


	
	
	
//	/**
//	 * 
//	 * @param userid被修改的用户account
//	 * @param doctorCode  产生修改操作的 doctor的code 
//	 * @param takeInfos
//	 * @throws Exception
//	 */
//	public void updateTakeinfoOfPatient(int userid,String doctorCode,String info) throws Exception{
//		//往本地暂存
//		File f = FileUtil.writeBytesToDisk(info.getBytes(),doctorCode ,userid+"");
//		//往缓存中存修改文件
//		FileCache.putCache(f.getName(),new FileDetail(f.getName(),f.getPath(),System.currentTimeMillis()));
//		//调用imservice发送给客户等待确认
//	}
//	public void confirm(String key) throws Exception {
//		if(FileCache.exists(key)){
//			//把缓存状态改变,为防止 定时器在 本方法读取文件时被删除 
//			FileCache.changeCacheStatus(key);
//			//双重保险
//			FileCache.exists(key);		
//			File file = new File(FileCache.getCache().get(key).getFileRealPath());
//			//从文件拿到json数据
//			String data = FileUtil.getDataFromFile(file);
//			//做操作
//			//删除
//			FileUtil.deleteOnDisk(new File(FileCache.getCache().get(key).getFileRealPath()));
//			FileCache.deleteCache(key);
//		}
//	}
//	public void cancel(String key) throws Exception {
//		if(FileCache.exists(key)){
//		//先把本地的副本删除 再删除缓存中的
//		File fileToRemove = new File(FileCache.getCache().get(key).getFileRealPath());
//		FileUtil.deleteOnDisk(fileToRemove);
//		FileCache.deleteCache(key);
//		}
//	}
	
	public User getUserByPatientId(int patientid) throws Exception{
		
		return patientMapper.selectUserByPatient(patientid);
		
	}
	

	
	
	
 
}
